<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2021/4/9
  Time: 16:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录页面</title>
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/xadmin.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/lib/layui/layui.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/xadmin.js"></script>
</head>
<body class="login-bg" onload="refreshCaptcha()">

<div class="login" >
    <div class="message">酒店管理系统-管理登录</div>
    <div id="darkbannerwrap"></div>


    <form class="layui-form">
        <input name="username" id="username" placeholder="用户名" type="text" class="layui-input">
        <hr class="hr15">
        <input name="password" id="password" placeholder="密码" type="password" class="layui-input">
        <hr class="hr15">
        <input id="code" placeholder="验证码" type="text" style="width:200px" class="layui-input layui-col-sm2 ">
        <img alt="验证码" th:src="@{/Captcha.jpg}" title="点击更换" id="captcha_img"/>
        <br>
        <a href="javascript:void(0)" onclick="javascript:refreshCaptcha()">验证码(看不清换一张)</a><br/>
        <hr class="hr15">
        <input value="登录" onclick="userLogin()" style="width:100%;" type="button">
        <a href="${pageContext.request.contextPath}/login/registPage">无账户？点击注册</a>
        <hr class="hr20">
    </form>



</div>

<script>
    //用户密码登录
    function userLogin() {
        var name = $("#username").val();
        var pwd = $("#password").val();
        var code=$("#code").val();
        $.ajax({
            url: "${pageContext.request.contextPath}/login/loginShiro",
            type: "post",
            data: {"userName": name, "userPassword": pwd,"code":code},
            contentType: "application/x-www-form-urlencoded",
            dataType: "json",
            success: function (data) {
                console.log(data);
                if (data.info == "登陆成功") {
                    window.location.href = "${pageContext.request.contextPath}/index1.jsp";
                    alert(data.info);
                } else {
                    alert(data.info);
                }

            }
        });
    }

    //刷新验证码
    function refreshCaptcha(){
        $("#captcha_img").attr("src","${pageContext.request.contextPath}/Captcha.jpg?id=" + new Date() + Math.floor(Math.random()*24));
    }
</script>

</body>
</html>
